package top.yjp.jtf.plugin;

import com.intellij.lexer.Lexer;
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors;
import com.intellij.openapi.editor.HighlighterColors;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.fileTypes.SyntaxHighlighterBase;
import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;

import static com.intellij.openapi.editor.colors.TextAttributesKey.createTextAttributesKey;

public class ExcelSyntaxHighlighter extends SyntaxHighlighterBase {
    public static final TextAttributesKey ENTITY_CLASS = 
            createTextAttributesKey("EXCEL_ENTITY_CLASS", DefaultLanguageHighlighterColors.CLASS_NAME);
    
    public static final TextAttributesKey PROPERTY = 
            createTextAttributesKey("EXCEL_PROPERTY", DefaultLanguageHighlighterColors.INSTANCE_FIELD);
    
    public static final TextAttributesKey OPERATOR = 
            createTextAttributesKey("EXCEL_OPERATOR", DefaultLanguageHighlighterColors.OPERATION_SIGN);
    
    public static final TextAttributesKey LOGIC_OPERATOR = 
            createTextAttributesKey("EXCEL_LOGIC_OPERATOR", DefaultLanguageHighlighterColors.OPERATION_SIGN);
    
    public static final TextAttributesKey STRING = 
            createTextAttributesKey("EXCEL_STRING", DefaultLanguageHighlighterColors.STRING);
    
    public static final TextAttributesKey NUMBER = 
            createTextAttributesKey("EXCEL_NUMBER", DefaultLanguageHighlighterColors.NUMBER);
    
    public static final TextAttributesKey KEYWORD = 
            createTextAttributesKey("EXCEL_KEYWORD", DefaultLanguageHighlighterColors.KEYWORD);
    
    public static final TextAttributesKey COMMENT = 
            createTextAttributesKey("EXCEL_COMMENT", DefaultLanguageHighlighterColors.LINE_COMMENT);
    
    public static final TextAttributesKey BAD_CHARACTER = 
            createTextAttributesKey("EXCEL_BAD_CHARACTER", HighlighterColors.BAD_CHARACTER);
    
    // 定义文本属性键数组，用于getTokenHighlights方法
    private static final TextAttributesKey[] ENTITY_CLASS_KEYS = new TextAttributesKey[]{ENTITY_CLASS};
    private static final TextAttributesKey[] PROPERTY_KEYS = new TextAttributesKey[]{PROPERTY};
    private static final TextAttributesKey[] OPERATOR_KEYS = new TextAttributesKey[]{OPERATOR};
    private static final TextAttributesKey[] LOGIC_OPERATOR_KEYS = new TextAttributesKey[]{LOGIC_OPERATOR};
    private static final TextAttributesKey[] STRING_KEYS = new TextAttributesKey[]{STRING};
    private static final TextAttributesKey[] NUMBER_KEYS = new TextAttributesKey[]{NUMBER};
    private static final TextAttributesKey[] KEYWORD_KEYS = new TextAttributesKey[]{KEYWORD};
    private static final TextAttributesKey[] COMMENT_KEYS = new TextAttributesKey[]{COMMENT};
    private static final TextAttributesKey[] BAD_CHAR_KEYS = new TextAttributesKey[]{BAD_CHARACTER};
    private static final TextAttributesKey[] EMPTY_KEYS = new TextAttributesKey[0];

    @NotNull
    @Override
    public Lexer getHighlightingLexer() {
        return new ExcelLexer();
    }

    @NotNull
    @Override
    public TextAttributesKey[] getTokenHighlights(IElementType tokenType) {
        if (tokenType == ExcelLexer.EXCEL_CONTENT) {
            return EMPTY_KEYS;
        }
        return EMPTY_KEYS;
    }
}